home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / portfoli / bootst11.lzh / PF BOOTSTRAP VATIPX PLOGC < prev    next >
Text File  |  1989-05-13  |  2KB  |  97 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)log.c    5.3 (Berkeley) 9/2/88";
  20. #endif /* not lint */
  21.  
  22. #include "tip.h"
  23. #include <grp.h>
  24.  
  25. #ifdef ACULOG
  26. static    FILE *flog = NULL;
  27.  
  28. #ifdef PRISTINE
  29. int pristine = 1;    /* so it is easier to change for binary-only sites */
  30. #else
  31. int pristine = 0;
  32. #endif
  33.  
  34. /*
  35.  * Log file maintenance routines
  36.  */
  37.  
  38. logent(group, num, acu, message)
  39.     char *group, *num, *acu, *message;
  40. {
  41.     static int uid = -1, gid = -1;
  42.     static char *user, *ugroup;
  43.     int i;
  44.       long t;
  45.     char *timestamp;
  46.     struct passwd *pwd;
  47.     struct group *grp;
  48.  
  49.     if (flog == NULL)
  50.         return;
  51.     if (flock(fileno(flog), LOCK_EX) < 0) {
  52.         perror("tip: flock");
  53.         return;
  54.     }
  55.     if (uid != (i = geteuid())) {
  56.         uid = i;
  57.         setpwent();
  58.         if ((pwd = getpwuid(getuid())) == NOPWD)
  59.             user = "???";
  60.         else
  61.             user = pwd->pw_name;
  62.     }
  63.     if (gid != (i = getgid())) {
  64.         gid = i;
  65.         setgrent();
  66.         if ((grp = getgrgid(getgid())) == (struct group *)0)
  67.             ugroup = "???";
  68.         else
  69.             ugroup = grp->gr_name;
  70.     }
  71.     t = time(0);
  72.     timestamp = ctime(&t);
  73.     timestamp[24] = '\0';
  74.     fprintf(flog, "%s:%s (%s) <%s, %s, %s> %s\n",
  75.         user, ugroup, timestamp, group,
  76.         pristine ? "" : num,
  77.         acu, message);
  78.     (void) fflush(flog);
  79.     (void) flock(fileno(flog), LOCK_UN);
  80. }
  81.  
  82. loginit()
  83. {
  84.     extern int errno;
  85.  
  86.       flog = fopen(value(LOG), "a");
  87.     if (flog == NULL) {
  88.         int e = errno;
  89.         fprintf(stderr, "tip: can't open log file: ");
  90.         errno = e;
  91.         perror(value(LOG));
  92.         putc('\r', stderr);
  93.         putc('\n', stderr);
  94.     }
  95. }
  96. #endif
  97.